//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    pageIndex: 1,
    pageCount: 0,
    booksData: {}
  },
  //事件处理函数
  onLoad: function () {
    this.getMyBooks();
  },
  getMyBooks: function(e) {
    wx.request({
      url: app.globalData.requestUrlPrefix+'BookHandlerService.ashx?method=Get_ON_Shelf_Books_From_UID', 
      data: {
         PageIndex: 1, 
         PageSize: 12
      },
      header: {
        'Cookie':app.globalData.sessionKeyStr,
        "content-type": app.globalData.contentTypeStr
      },
      success: res => {
        for (var i = 0; i < res.data.rows.length; i++) {
            var str = res.data.rows[i]["Descript"];
            res.data.rows[i]["Descript"] = (str.length <= 140) ? str : (str.substr(0, [(140 - 1)]) + "...");
         }
        //console.log(res.data);
        this.setData({
          pageCount: res.data.PageCount,
          pageIndex: res.data.PageIndex,
          booksData: res.data.rows
        })
      }
    })
  },

  bindBookap: function (e) {
    wx.request({
      url: app.globalData.requestUrlPrefix + 'BookHandlerService.ashx?method=Get_One_Book_Info_From_BID',
      data: {
        BID: BID
      },
      header: {
        "content-type": app.globalData.contentTypeStr
      },
      method: "GET",
      success: res => {
        console.log(res.data);
      }
    })
  },
})
